<template>

  <el-row>
    <el-col :span="12">
      <div class="grid-content bg-purple">
        <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
          <el-form-item>
            <el-input v-model="dataForm.key" placehotlder="参数名" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button @click="getDataList()" type="primary" icon="el-icon-search">查询</el-button>

            <el-button type="primary" icon="el-icon-edit" @click="addOrHandle()">新增</el-button>
            <el-button type="primary" icon="el-icon-delete" @click="deleteHandle()">删除</el-button>

          </el-form-item>
        </el-form>
        <div>
          <el-tree
            @node-click="addOrHandle"
            :data="data"
            show-checkbox
            check-strictly
            :default-expand-all="flag"
            node-key="id"
            ref="tree"
            highlight-current
            :props="defaultProps"
          >
          </el-tree>
        </div>
      </div>
    </el-col>

    <el-col :span="12">
      <div class="grid-content bg-purple-light">
        <add-or-update v-if="deleteHandle" ref="addOrUpdate" @refreshDataList="getDataList()"></add-or-update>
      </div>
    </el-col>
  </el-row>
</template>

<script>
import {getcoreorgList} from '@/api/coreorg.js'
import AddOrUpdate from "./coreorg-add-or-update";

export default {

  data() {
    return {
      flag: false,
      data: [],
      expandedKeys: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      dataForm: {
        key: ''
      },

      dataList: [],
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      addHandle: false
    };
  },
  components: {
    AddOrUpdate,

  },

  methods: {
    coreorg(e) {

    },

    getMenus() {
      this.$http({
        url: this.$http.adornUrl('/auth/coreorg/list/tree'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          'name': this.dataForm.beanName
        })
      }).then(({data}) => {
        this.data = data.page;
      });
    },


    getDataList() {

      let params = {
        'page': this.pageIndex,
        'limit': this.pageSize,
        'name': this.dataForm.key
      }
      getcoreorgList(params).then(({data}) => {
        this.data = data.page
        console.log("dfsfsfdsfsdfsdf",data)
      })
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val
    },
    // 新增 / 修改x
    addOrHandle(e) {

      this.$nextTick(() => {
        if (!e == "") {
          this.$refs.addOrUpdate.init(e.id)

        } else {
          this.$refs.addOrUpdate.init()
        }

      })
      this.addOrUpdateVisible = true

    },
    // 删除
    deleteHandle() {
      var checkedKeys = this.$refs.tree.getCheckedKeys();
      var ids = checkedKeys ? [checkedKeys] : this.dataListSelections.map(item => {
        return item.checkedKeys
      })
      this.$confirm(`确定对删除吗?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl("/auth/coreorg/delete"),
          method: 'post',
          data: this.$http.adornData(checkedKeys, false)
        }).then(({data}) => {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList()
              }
            })
        })
      })
    }
  },
  mounted() {
    this.getMenus();
  },
};
</script>


